package com.zc.custom;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;

@Component
public class CustomApplicationRunner implements ApplicationRunner, ApplicationEventPublisherAware {
    @Value("${name}")
    private String name;

    private ApplicationEventPublisher publisher;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println(name + "发布CongEvent");
        publisher.publishEvent(new CongEvent(publisher, "聪聪，你还好吗"));
    }

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.publisher = applicationEventPublisher;
    }
}
